package example.utils;

import example.dao.UserDao;
import example.domain.User;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;

@WebServlet(name = "ServletFindAllUserTest",value = "/ServletFindAllUserTest")
public class ServletFindAllUserTest extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request,
                         HttpServletResponse response)
            throws ServletException, IOException{
        UserDao usersDao=new UserDao();

        ArrayList<User>list=usersDao.findAll();
        PrintWriter out =response.getWriter();
        for (int i = 0; i < list.size();i++){
            out.print("user"+(i+1)+":"+list.get(i).getUsername());
            out.print("</br>");
        }
    }
    @Override
    protected void  doPost(HttpServletRequest request,
                           HttpServletResponse response)
            throws ServletException,IOException{

    }
}
